/**
 * Created by Administrator on 2016/12/23 0023.
 */

var ObjectId=require("mongodb").ObjectID;
var Book=require("../models/Book.js");
exports.showIndex= function (req, res, next) {
    Book.findAll(function (err,result) {
       // console.log(result);
        res.render("index",{
            "books":result
        })
    });

}
exports.addbook= function (req, res, next) {
    res.render("addbook");

}
exports.doaddbook= function (req, res, next) {
    console.log(req.query)
    Book.create(req.query, function (err) {
        res.send("成功了...");
    })
}
exports.edit= function (req, res, next) {
    //Book.findByName(req.query.name, function (err,result) {
    Book.findById(req.query.id, function (err,result) {
      //  console.log(req.query.id);
     //   console.log(result);
        res.render("edit",{
            "name":result[0].name,
            "author":result[0].author,
            "price":result[0].price
        })
    })
    //res.render("edit");
}